package com.jiutong.meipengdai.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jiutong.meipengdai.R;
import com.jiutong.meipengdai.entity.MsgCenterRespond;

import java.util.List;


/**
 * 作用:
 * Created by 78 on 2017/6/9.
 */
public class MsgAdapter extends RecyclerView.Adapter<MsgAdapter.MsgViewHolder> {

    private Context context;
    private List<MsgCenterRespond.DataBean.MessagesBean> list;

    public MsgAdapter(Context mContext, List<MsgCenterRespond.DataBean.MessagesBean> list) {
        this.context = mContext;
        this.list = list;
    }

    @Override
    public MsgAdapter.MsgViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message, parent, false);
        MsgViewHolder holder = new MsgViewHolder(view);
        holder.tv_msg_time = (TextView) view.findViewById(R.id.tv_msg_time);
        holder.tv_msg_title = (TextView) view.findViewById(R.id.tv_msg_title);
        holder.tv_msg_content = (TextView) view.findViewById(R.id.tv_msg_content);
        return holder;
    }

    @Override
    public void onBindViewHolder(MsgViewHolder holder, int position) {
        holder.tv_msg_title.setText(list.get(position).getTheme());
        holder.tv_msg_content.setText(list.get(position).getContent());
        holder.tv_msg_time.setText(list.get(position).getTime());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MsgViewHolder extends RecyclerView.ViewHolder {

        public MsgViewHolder(View itemView) {
            super(itemView);
        }

        TextView tv_msg_time;
        TextView tv_msg_title;
        TextView tv_msg_content;
    }

}
